import SystemUtil from 'utils/systemUtil';

export default {
  data() {
    return {
      timeoutList: [],
      isDestroy:false
    };
  },

  beforeDestroy() {
    this.clearTimeoutList();
    this.isDestroy = true;
  },

  methods: {
    clearTimeoutList(index) {
      let timeoutList = this.timeoutList;
      if (index !== undefined) {
        let timeout = timeoutList[index];
        if (!SystemUtil.isEmpty(timeout)) {
          clearTimeout(timeout);
          timeoutList[index] = null;
        }
        return;
      }
      if (timeoutList.length > 0) {
        for (let i = 0; i < timeoutList.length; i++) {
          let timeout = timeoutList[i];
          if (!SystemUtil.isEmpty(timeout)) {
            clearTimeout(timeout);
          }
        }
        this.timeoutList = [];
      }
    }
  }
};
